<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="125px">
      <el-form-item label="订单编号" prop="orderCode">
        <el-input v-model="queryParams.orderCode" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学员名称" prop="sName">
        <el-input v-model="queryParams.sName" placeholder="请输入学员名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="变动方式" prop="tyep">
        <el-select v-model="queryParams.tyep" placeholder="请选择变动方式" clearable @keyup.enter.native="handleQuery">
          <el-option label="出" value="0" />
          <el-option label="入" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="变动类型" prop="genre">
        <el-select v-model="queryParams.genre" placeholder="请选择变动类型" clearable @keyup.enter.native="handleQuery">
          <el-option label="销课" value="1" />
          <el-option label="退课" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="变动描述" prop="datil">
        <el-input v-model="queryParams.datil" placeholder="请输入变动描述" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="StudentChangeList" @selection-change="handleSelectionChange">
      <el-table-column label="订单编号" align="center" prop="orderCode" />
      <el-table-column label="学员名称" align="center" prop="stuName" />
      <el-table-column label="变动方式" align="center" prop="tyep">
        <template slot-scope="scope">
          {{scope.row.tyep === '0' ? '出' : '入'}}
        </template>
      </el-table-column>
      <el-table-column label="变动类型" align="center" prop="genre">
        <template slot-scope="scope">
          {{scope.row.genre === '1' ? '消课' : '退课'}}
        </template>
      </el-table-column>
      <el-table-column label="变动前课时" align="center" prop="beforTimeNum" />
      <el-table-column label="变动课时" align="center" prop="changeTimeNum" />
      <el-table-column label="变动后课时" align="center" prop="afterTimeNum" />
      <el-table-column label="变动描述" align="center" prop="datil" />
      <el-table-column label="时间" align="center" prop="createTime" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listStudentChange, getStudentChange, delStudentChange, addStudentChange, updateStudentChange } from "@/api/course/StudentChange";

export default {
  name: "StudentChange",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学员课程变动表格数据
      StudentChangeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        sId: null,
        sCode: null,
        sName: null,
        tyep: null,
        genre: null,
        beforTimeNum: null,
        changeTimeNum: null,
        afterTimeNum: null,
        datil: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学员课程变动列表 */
    getList() {
      this.loading = true;
      listStudentChange(this.queryParams).then(response => {
        this.StudentChangeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderCode: null,
        sId: null,
        sCode: null,
        sName: null,
        tyep: null,
        genre: null,
        beforTimeNum: null,
        changeTimeNum: null,
        afterTimeNum: null,
        datil: null,
        createBy: null,
        createTime: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员课程变动";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudentChange(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学员课程变动";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStudentChange(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudentChange(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学员课程变动编号为"' + ids + '"的数据项？').then(function () {
        return delStudentChange(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('course/StudentChange/export', {
        ...this.queryParams
      }, `StudentChange_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
